package com.axend.aerosense.base.utils;

import android.util.Log;

/**
 * 日志工具
 */
public class LogUtils {

    /**
     * 当前log等级
     * 0：不显示log
     */
    private static int CURRENT_LEV = 0;

    /**
     * 只显示某一等级的log
     * CURRENT_LEV 设置为0才起作用
     */
    private static int SINGLE_LOG = 0;

    private static final int DEBUG_LEV = 4;
    private static final int INFO_LEV = 3;
    private static final int WARNING_LEV = 2;
    private static final int ERROR_LEV = 1;

    public static void d(Object obj, Object msg){
        if (CURRENT_LEV >= DEBUG_LEV || SINGLE_LOG == DEBUG_LEV)
            printLog(DEBUG_LEV, obj, msg);
    }

    public static void i(Object obj, Object msg){
        if (CURRENT_LEV >= INFO_LEV || SINGLE_LOG == INFO_LEV)
            printLog(INFO_LEV, obj, msg);
    }

    public static void w(Object obj, Object msg){
        if (CURRENT_LEV >= WARNING_LEV || SINGLE_LOG == WARNING_LEV)
            printLog(WARNING_LEV, obj, msg);
    }

    public static void e(Object obj, Object msg){
        if (CURRENT_LEV >= ERROR_LEV || SINGLE_LOG == ERROR_LEV)
            printLog(ERROR_LEV, obj, msg);
    }

    private static void printLog(int level, Object object, Object msg){
        String tag = object.getClass().getCanonicalName() + "---------->";
        String content = msg.toString();
        switch (level){
            case DEBUG_LEV :
                Log.d(tag, content);
                break;
            case INFO_LEV :
                Log.i(tag, content);
                break;
            case WARNING_LEV :
                Log.w(tag, content);
                break;
            case ERROR_LEV :
                Log.e(tag, content);
                break;
        }
    }

}
